package hos.http;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * <p>Title: HttpCallback </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2023-02-23 14:42
 */
public abstract class HttpCallback<T> {
    public abstract void onSuccess(HttpRequest<?> request, T response);

    public abstract void onFailed(Throwable throwable);


    public Type checkType(Type type, Class<?> callback) {
        if (type != null) {
            return type;
        }
        if (callback != null) {
            Type genType = callback.getGenericSuperclass();
            if (genType != null) {
                type = ((ParameterizedType) genType).getActualTypeArguments()[0];
            }
            if (type == null) {
                throw new RuntimeException("type is not null");
            }
            return type;
        }
        return null;
    }
}
